package com.ruoyi.project.schedule.taskfinish.controller;

import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.schedule.task.domain.Task;
import com.ruoyi.project.schedule.task.service.TaskServiceImpl;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/schedule/taskfinish")
public class TaskFinishController extends BaseController {

    private String prefix = "schedule/taskfinish";

    @Autowired
    private TaskServiceImpl taskService;


    /**
     * 显示当前用户的任务列表
     * @return
     */
    @RequiresPermissions("schedule:taskfinish:view")
    @GetMapping
    public String ShowTask(){
        return prefix + "/taskfinish";
    }

    /**
     * 显示所有任务(完成者)
     * @param task
     * @return
     */
    @RequiresPermissions("schedule:taskfinish:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Task task) {
        task.setTaskUserId(ShiroUtils.getUserId());
        startPage();
        return getDataTable(taskService.selectTaskListFinished(task));
    }

    /**
     * 查看任务
     * @param taskId
     * @param mmap
     * @return
     */
    @GetMapping("/edit/{taskId}")
    public String edit(@PathVariable("taskId") Long taskId, ModelMap mmap) {
        mmap.put("task", taskService.selectByTaskId(taskId));
        return prefix + "/edit";
    }

    /**
     * 完成任务
     * @param task
     * @return
     */
    @RequiresPermissions("schedule:taskfinish:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Task task){
        return taskService.updateTaskBy(task);
    }

}
